% =========================================================================
% 这个脚本主要用来确定如何实现模拟调制带宽信息的标注问题
% =========================================================================
clc
clear
close all

samplePerFrame = 200000*6;
sampleRate = 200e3;

audioSrc = dsp.AudioFileReader('E:\Projects\ChangShuoRadioData\csrd\transceiver\source\audio_mix_441.wav', ...
    'SamplesPerFrame', samplePerFrame, 'PlayCount', inf);
audioRC = dsp.SampleRateConverter('Bandwidth', 30e3, ...
    'InputSampleRate', audioSrc.SampleRate, ...
    'OutputSampleRate', sampleRate);
[~, decimFactor] = getRateChangeFactors(audioRC);
audioSrc.SamplesPerFrame = ceil(samplePerFrame / ...
    sampleRate * audioSrc.SampleRate / ...
    decimFactor) * decimFactor;

x1 = audioRC(audioSrc());

bw = obw(x1, sampleRate);
x2 = lowpass(x1, bw, sampleRate, ImpulseResponse = "fir", Steepness = 0.99999, StopbandAttenuation=200);

DUC = dsp.DigitalUpConverter(...
    InterpolationFactor = 5,...
    SampleRate = sampleRate,...
    Bandwidth = 2*bw,...
    StopbandAttenuation = 100,...
    PassbandRipple = 0.1,...
    CarrierFrequency = 400e3);

DDC = dsp.DigitalDownConverter(...
    'DecimationFactor',5,...
    'SampleRate', sampleRate*5,...
    'Bandwidth', 2*bw,...
    'StopbandAttenuation', 100,...
    'PassbandRipple',0.1,...
    'CarrierFrequency',400e3);
    
x3 = DUC(complex(x2));
x4 = real(DDC(x3));
